package activity

import (
	"context"

	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"
	"mall/service/promotion/rpc/promotionclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteActivityProductLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeleteActivityProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteActivityProductLogic {
	return &DeleteActivityProductLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteActivityProductLogic) DeleteActivityProduct(
	req *types.DeleteActivityProductReq,
) (resp *types.BaseMsgResp, err error) {
	if req.ActivityId != nil && *req.ActivityId > 0 && len(req.SkuIds) > 0 {
		res, err := l.svcCtx.PromotionRpc.BackendDeleteActivityProduct(l.ctx, &promotionclient.ActivityRelationshipInfo{
			ActivityId: *req.ActivityId,
			SkuIds:     req.SkuIds,
		})
		if err != nil {
			return nil, err
		}

		return &types.BaseMsgResp{
			Success: true,
			Msg:     l.svcCtx.Trans.Trans(l.ctx, res.Msg),
		}, nil
	}

	return
}
